using JT808Protocol.Common;
using System;
using System.Collections.Generic;
using System.Text.Json.Serialization;

namespace JT808Protocol.Models.BodyParserStrategy
{
    public class DpAvResourceList_0x1205 : IJT808Body
    {
        /// <summary>
        /// 流水号
        /// </summary>
        [JsonPropertyName("流水号")] public ushort Sn { get; set; }

        /// <summary>
        /// 资源数
        /// </summary>
        [JsonPropertyName("资源数")] public uint ResourceCount { get; set; }

        /// <summary>
        /// 资源列表
        /// </summary>
        [JsonPropertyName("资源列表")] public List<ItemAvResource> ResourceList { get; set; }

        public override IJT808Body ReadBody(ReadOnlySpan<byte> data, ref int index)
        {
            //流水号
            Sn = ParseHelper.Uint16(ref data, index);

            //资源数
            index += 2;
            ResourceCount = ParseHelper.Uint32(ref data, index);

            //资源列表
            index += 4;
            ResourceList = new List<ItemAvResource>();
            for (int i = 1; i <= ResourceCount; i++)
            {
                ItemAvResource res = new ItemAvResource();
                res.ReadBuffer(ref data, index);
                ResourceList.Add(res);

                index += 28;
            }

            return this;
        }

        public override List<byte> WriteToBytes()
        {
            throw new NotImplementedException();
        }
    }
}